/*
 * @Author: 徐建辰
 * @LastEditors: 徐建辰
 * @Description: 工具集，比较杂
 */
import {isObject, isNumber, isArray} from './type'

// 复制对象
export const objCopy = obj => {
  if (!isObject(obj)) {
    throw new Error(`params must be object, not ${typeof obj}`)
  }
	return JSON.parse(JSON.stringify(obj))
}

// 千分符
export const groupSeparator = num => {
  if (!isNumber(num)) {
    throw new Error(`params must be number, not ${typeof obj}`)
  }
	num = num + ''
	if (!num.includes('.')) {
		num += '.'
	}
	return num.replace(/(\d)(?=(\d{3})+\.)/g, function ($0, $1) {
		return $1 + ','
	}).replace(/\.$/, '')
}

// 判断是否是外部资源
export function isExternal(path) {
  return /^(https?)/.test(path)
}